// pages/map/map.js
import QQMapWX from "../../qqmap-wx-jssdk"

var qqmapsdk = new QQMapWX({
  key: 'XSLBZ-DV22I-KDZG2-UUCPL-24D4Z-ZXF6F' // 必填
});
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: false,
    longitude: '',
    latitude: '',
    address: '',
    markers: [{
      longitude: '113.61332',
      latitude: '34.74821',
      id: 0,
      width: 34,
      height: 49,

    }],

  },

  toclick() {
    console.log('123');

    this.setData({
      isShow: !this.data.isShow
    })

  },

  toaddress() {
    var that = this;
    wx.chooseLocation({
      success(res) {
        console.log(res);
        let index = 0;
        let change = "markers[" + index + "].longitude";
        let changes = "markers[" + index + "].latitude";
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
          address: res.name,
          [change]: res.longitude,
          [changes]: res.latitude
        })

      }
    })
  },
  nav() {
    wx.chooseLocation({
      success(res){
console.log(res);
wx.openLocation({
  latitude:res.latitude,
  longitude:res.longitude,
  name:res.name,
  address:res.address
 })
      }
    })

   
    
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this

    qqmapsdk = new QQMapWX({
        key: 'XSLBZ-DV22I-KDZG2-UUCPL-24D4Z-ZXF6F'
      }),
      wx.getLocation({
        type: 'wgs84',

        success: function (res) {
          console.log('维度', res.latitude);
          console.log('经度', res.longitude);
          that.setData({
            latitude: res.latitude,
            longitude: res.longitude,
          })


          var _this = this;
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: res.latitude,
              longitude: res.longitude

            },
            success: function (res) {
              console.log(res);
              that.setData({
                address: res.result.address

              })
            }
          })
        }
      })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    qqmapsdk.search({
      keyword: '酒店',
      success: function (res) {
        console.log(res);
      },
      fail: function (res) {
        console.log(res);
      },
      complete: function (res) {
        console.log(res);
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})